package com.lxp.design.shop.order.kafka.sender;

import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author LaiXiaoPeng
 * @version 1.0
 * @date 2022/9/14 16:25
 */
@Component
public class KafkaSender {
    @Resource
    private KafkaTemplate<String,Object> kafkaTemplate;

    @Transactional(rollbackFor = Exception.class)
    public void sendMsg(String topic,String key,Object msg){
        kafkaTemplate.send(new ProducerRecord<>(topic,key,msg));
//        throw new RuntimeException("send failed");
    }
}
